﻿using System.Linq;
using TMV.Models.Input;
using TMV.Repositories;
using TMV.UnitOfWork;

namespace TMV.Services
{
    public interface ICategoryService : IApplicationService<Category>
    {
        Category GetByName(string name);
    }

    public class CategoryService : ApplicationService<Category>, ICategoryService
    {
        IUnitOfWork unitOfWork;
        ICategoryRepository categoryRepository;

        public CategoryService(IUnitOfWork unitOfWork, ICategoryRepository categoryRepository)
            : base(unitOfWork, categoryRepository)
        {
            this.unitOfWork = unitOfWork;
            this.categoryRepository = categoryRepository;
        }

        public Category GetByName(string name)
        {
            return categoryRepository.Get(x => x.Name == name).FirstOrDefault();
        }
    }
}